const fs = require('fs');
const path = require('path');
var https = require('https')
const express = require('express')

const app = express()
const httpsOptions = {
    key: fs.readFileSync("ssl/wutianci.cn.key", 'utf8'),
    cert: fs.readFileSync("ssl/wutianci.cn.crt", 'utf8')
}
//创建路由实例，我们可以在该实例上自由的添加路由
// let usersRouter = express.Router();
// let orderRouter = express.Router();
 
//添加两个路由到应用上
// app.use('/users', usersRouter);
// app.use('/order', orderRouter);

const SSL_PORT = 443;
app.use(express.static(path.join(__dirname, 'public')))
const process = require('child_process');
app.get('/pl', (req, res)=>{
    process.exec('git pull',function (error, stdout, stderr) {
        if (error !== null) {
          console.log('exec error: ' + error);
          res.end('exec error: ' + error) 
        }
        res.end('success1') 
    });
    
})
app.get('/rs', (req, res)=>{
    process.exec('pm2 restart 1',function (error, stdout, stderr) {
        if (error !== null) {
          console.log('exec error: ' + error);
          res.end('exec error: ' + error) 
        }
        
    });
    res.end('restart success') 
    
})


https.createServer(httpsOptions, app).listen(SSL_PORT, () => {
    console.log('--')
})
app.listen(80,()=>{
    console.log('asd')
})